#include "../Tools/GLHeaders.hpp"
#include "ModelLeftArm.hpp"
#include <cmath>

ModelLeftArm::ModelLeftArm(void){
	activate = false;	
  list_id = glGenLists(1); // create one DisplayList
  glNewList(list_id, GL_COMPILE);
  GLUquadricObj *quadratic = gluNewQuadric();
  gluQuadricNormals(quadratic, GLU_SMOOTH);

  GLfloat pt00[] = { 3.25f,-5.25f, 0.75f};
  GLfloat pt01[] = { 1.75f,-5.25f, 0.75f};
  GLfloat pt02[] = { 1.75f,-5.25f,-0.75f};
  GLfloat pt03[] = { 3.25f,-5.25f,-0.75f};

  GLfloat pt10[] = { 3.0f,-0.5f, 0.5f};
  GLfloat pt11[] = { 2.0f,-0.5f, 0.5f};
  GLfloat pt12[] = { 2.0f,-0.5f,-0.5f};
  GLfloat pt13[] = { 3.0f,-0.5f,-0.5f};

  GLfloat pt20[] = { 3.5f,-1.25f, 1.0f};
  GLfloat pt21[] = { 1.5f,-1.25f, 1.0f};
  GLfloat pt22[] = { 0.5f,-0.75f, 1.0f};
  GLfloat pt23[] = { 0.5f, 0.75f, 1.0f};
  GLfloat pt24[] = { 2.5f, 1.25f, 1.0f};
  GLfloat pt25[] = { 3.5f, 0.25f, 1.0f};

  GLfloat pt30[] = { 3.5f,-1.25f,-1.0f};
  GLfloat pt31[] = { 1.5f,-1.25f,-1.0f};
  GLfloat pt32[] = { 0.5f,-0.75f,-1.0f};
  GLfloat pt33[] = { 0.5f, 0.75f,-1.0f};
  GLfloat pt34[] = { 2.5f, 1.25f,-1.0f};
  GLfloat pt35[] = { 3.5f, 0.25f,-1.0f};

  glBegin(GL_TRIANGLES);
  //Left Arm
  glNormal3f( 0.0f, 0.0f, 1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11); // Front
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);

  glNormal3f(-1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12); // Left
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);

  glNormal3f( 0.0f, 0.0f,-1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13); // Back
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);

  glNormal3f( 1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10); // Right
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);

  glNormal3f( 0.0f,-1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00); // Botton
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);

  //Elbow
  glNormal3f( 0.0f, 0.0f, 1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt22); // Front
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt21);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt20);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt24);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt23);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt22);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt20);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt25);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt24);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt24);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt22);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt20);

  glNormal3f( 0.0f, 0.0f,-1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt30); // Back
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt31);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt32);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt32);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt33);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt34);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt34);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt35);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt30);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt30);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt32);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt34);

  glNormal3f( 0.0f,-1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt20); // Bottom
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt21);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt31);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt31);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt30);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt20);

  glNormal3f( cosf(2.0f*M_PI/3.0f), sinf(2.0f*M_PI/3.0f), 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt33); // Top
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt23);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt24);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt24);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt34);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt33);
  glNormal3f( cosf(M_PI/4.0f), sinf(M_PI/4.0f), 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt34);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt24);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt25);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt25);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt35);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt34);

  glNormal3f( cosf(-2.0f*M_PI/3.0f), sinf(-2.0f*M_PI/3.0f), 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt32); // Left
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt31);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt21);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt21);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt22);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt32);
  glNormal3f(-1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt33);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt32);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt22);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt22);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt23);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt33);

  glNormal3f( 1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt25); // Right
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt20);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt30);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt30);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt35);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt25);

  glEnd();
  glTranslatef( 2.5f, -5.5f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);
  gluSphere(quadratic, 1.0f, 16, 16);
  glTranslatef(-2.5f, 5.5f, 0.0f);
  glEndList();
 }

ModelLeftArm::~ModelLeftArm(void){
  glDeleteLists(list_id,1);
}

void ModelLeftArm::Draw(void){
	glPushAttrib(GL_COLOR_BUFFER_BIT|GL_CURRENT_BIT|GL_TEXTURE_BIT);	
	glDisable(GL_TEXTURE_2D); 
	if(activate)
		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	else
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

  glCallList(list_id);
	glPopAttrib();
}

void ModelLeftArm::Activate(void){
	activate = true;
}

void ModelLeftArm::Desactivate(void){
	activate = false;
}
